﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using Texfina.Core.Common;  
using Texfina.Core.Web;
using Texfina.Common.Mg;
using Texfina.Core.Data;  
using Texfina.Entity.Rh;
using Texfina.Entity.Mg;
using RHBOQry = Texfina.BOQry.Rh;
using MGBOQry = Texfina.BOQry.Mg;

namespace RH
{
   public partial class wfProcPlaCtaCteBnd : SearchPage 
   {
       public const int _GRDLIST_STANULADO = 8;
       public const int _GRDLIST_STPROCESO = 9;
    
      protected void Page_Load(object sender, EventArgs e)
      {
                       
         this.LoadInitialSettings();
         if(this.IsPostBack){
            this.LoadInPostBack();
            return;
         } 

         this.LoadData();

      }

      public override void LoadInitialSettings()
      {
         Label lbl = (Label) this.Master.FindControl("lblTitle");
         lbl.Text = "Descuentos Cta.Cte.";
         this.Page.Form.DefaultButton = bttSearch.UniqueID;
      }

      public override void LoadListControls()
      {
          ETablaGenDet objEDet = new ETablaGenDet();
          MGBOQry.ITablaGen objBOI = (MGBOQry.ITablaGen)WCFHelper.GetObject<MGBOQry.ITablaGen>(typeof(MGBOQry.TablaGen));

          objEDet.IdTabla = ConstMultitabla.MES;
          DataTable dt = objBOI.GetDetailByList(objEDet);
          WebHelper.LoadListControl(ddlidMes, dt, "dsDescrip", "idCodigo", true, true);

          objEDet.IdTabla = ConstMultitabla.FORMA_PAGO;
          dt = objBOI.GetDetailByList(objEDet);
          WebHelper.LoadListControl(ddlidForPago, dt, "dsDescrip", "idCodigo", true, true);

      }


      public override void SearchData()
      {
          EProcPlaniBandeja objE = new EProcPlaniBandeja();

          objE.IdPeriodo= Session[ConstSessionVar.PERIODO].ToString();
          objE.IdEmpresa= Session[ConstSessionVar.EMPRESA].ToString();

          if (this.ddlidMes.SelectedValue.ToString() == "")
              objE.IdMes = null;
          else
              objE.IdMes = this.ddlidMes.SelectedValue.ToString();

          if (this.ddlidForPago.SelectedValue.ToString() == "")
              objE.IdForPago = null;
          else
              objE.IdForPago = this.ddlidForPago.SelectedValue.ToString();

          if (this.txtidPlanilla.Text == "")
              objE.IdPlanilla = null;
          else
              objE.IdPlanilla = this.txtidPlanilla.Text;

          if (this.txtdsPlanilla.Text == "")
              objE.DsPlanilla = null;
          else
              objE.DsPlanilla = this.txtdsPlanilla.Text;

          IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.ProcPlani));
          DataTable dt = objBO.GetByCriteria(objE);

          this.GridSetDataBinding(grdList, dt);

      }

      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
          String strQS= "";

         switch(e.Item.Value){
            case ConstMenuToolbarValue.BUTTON_NEW:
               strQS = "wfProcPlaCtaCteMnt.aspx?formEA=" + Convert.ToInt32(FormEditAction.AddNew).ToString();
               break; 
         }
         Response.Redirect(strQS);
      }

      protected void grdList_RowCommand(Object sender, GridViewCommandEventArgs e)
      { 
         DataRow dr = this.GridGetRowFromDataKey(grdList, Convert.ToInt32(e.CommandArgument));
         FormEditAction formEA= FormEditAction.AddNew;

         switch(e.CommandName)
         {
             case ConstGridRowCommand.GRIDEDIT:
               formEA = FormEditAction.Edit;
               break;
             case ConstGridRowCommand.GRIDDELETE:
               formEA = FormEditAction.Delete;
               break;
             case ConstGridRowCommand.GRIDPREVIEW:
               //this.PrintReport(Convert.ToInt32(e.CommandArgument));
               return;
         }
         String strQS = "wfProcPlaCtaCteMnt.aspx?formEA=" + Convert.ToInt32(formEA).ToString() 
             + "&IdMes=" + dr["idMes"].ToString() + "&IdForPago=" + dr["idForPago"].ToString()
             + "&IdPlanilla=" + dr["idPlanilla"].ToString() + "&NuProcAnual=" + dr["nuProcAnual"].ToString();
         Response.Redirect(strQS);
      
      }

      protected void grdList_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              String strRI = e.Row.RowIndex.ToString();

              ImageButton bttedit = (ImageButton)e.Row.FindControl("grdBtt" + ConstGridRowCommand.GRIDEDIT);

              if (e.Row.Cells[_GRDLIST_STANULADO].Text == ConstFlagEstado.ACTIVADO)
              {
                  e.Row.ForeColor = System.Drawing.Color.Red;
              }
              else
              {
                  if (e.Row.Cells[_GRDLIST_STPROCESO].Text == ConstEstadoProcePlani.CERRADA)
                  {
                      e.Row.ForeColor = System.Drawing.Color.Blue;
                  }
              }
          }

      }
      protected void bttOk_Click(object sender, EventArgs e)
      {
          this.SearchData();
      }
   }
}